# --*-- coding: utf-8 --*--

"""
Author: Darker
Description: 从响应中提取某个key对应的值
Version: 0.0.1
LastUpdateDate: 2021-07-13
UpdateURL:
LOG:
"""

value = None


class GetValues(object):
	@staticmethod
	def get_dict(dict1, values):
		global value  # 定义全局变量
		values1 = values
		for k, v in dict1.items():
			if k == values:
				value = v
				break
			elif isinstance(v, list):  # 判断类型是不是list
				GetValues.get_list(v, values1)
			elif isinstance(v, dict):
				GetValues.get_dict(v, values1)
			else:
				continue
		return value

	@staticmethod
	def get_list(list1, values1):
		for i in list1:
			if isinstance(i, list):
				GetValues.get_list(i)

			elif isinstance(i, dict):
				GetValues.get_dict(i, values1)
			else:
				continue

	@staticmethod
	def get_value_from_json_dict(_obj, key):
		ret = []

		def _get_value_from_json_dict(_obj, _key):
			if isinstance(_obj, list):
				for _i in _obj:
					_get_value_from_json_dict(_i, _key)
			elif isinstance(_obj, dict):
				for _k, _v in _obj.items():
					if _k == _key:
						ret.append(_v)
					else:
						_get_value_from_json_dict(_v, _key)
			else:
				return

		_get_value_from_json_dict(_obj, key)

		return ret


if __name__ == "__main__":
	d = {
		"total": 26368,
		"list": [
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003030",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "473cb8b650a84cbb96d3fd9ebd651c06",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "473cb8b650a84cbb96d3fd9ebd651c06",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100151",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030302020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:54",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:54",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003028",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "d7c8744bfc9e4ccd95ecee4d5e677307",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "d7c8744bfc9e4ccd95ecee4d5e677307",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100258",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030282020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:53",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:53",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003029",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "406f06e34f76480f8dfae0fa18075ef4",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "406f06e34f76480f8dfae0fa18075ef4",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100261",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030292020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:53",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:53",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003022",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "9e4c8428fe5141ef867d8cf734f09c09",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "9e4c8428fe5141ef867d8cf734f09c09",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100184",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030222020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:52",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:52",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003023",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "82c5a83b907d4501b964534e24649a68",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "82c5a83b907d4501b964534e24649a68",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100163",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030232020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:52",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:52",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8010001239",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "f0d71e345b5747e3bc2c4a32a07f6237",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "f0d71e345b5747e3bc2c4a32a07f6237",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XA",
				"boeNum": "CTG-JX20123100191",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200180100012392020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:51",
				"voucherName": "【CTG】共享系统-收款过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-收款过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:51",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003021",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "d7c1f5718101454bb9605434ea7c4683",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "d7c1f5718101454bb9605434ea7c4683",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100185",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030212020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:51",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:51",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003020",
				"enabled": "Y",
				"userDate": "2020-12-31 00:00:00",
				"approverName": None,
				"voucherId": "91bc31079e37484bbd9fea24def5c5a1",
				"voucherDate": "2020-12-31 00:00:00",
				"id": "91bc31079e37484bbd9fea24def5c5a1",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20123100118",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030202020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:51",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:51",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003016",
				"enabled": "Y",
				"userDate": "2020-12-28 00:00:00",
				"approverName": None,
				"voucherId": "f329df72525f4a34be47b2b545f55eca",
				"voucherDate": "2020-12-28 00:00:00",
				"id": "f329df72525f4a34be47b2b545f55eca",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20122800657",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030162020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:50",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:50",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "CNY"
			},
			{
				"userNum": "99990008/SIT",
				"groupId": "accba517-5725-4fae-8938-48946676bfc1",
				"companyName": "中国旅游集团旅行服务有限公司",
				"periodName": "202012",
				"voucherNum": "8200003015",
				"enabled": "Y",
				"userDate": "2020-12-28 00:00:00",
				"approverName": None,
				"voucherId": "32f983b0eb4646fa9e710be47fe5dde6",
				"voucherDate": "2020-12-28 00:00:00",
				"id": "32f983b0eb4646fa9e710be47fe5dde6",
				"companyCode": "2001",
				"createdUserId": "",
				"voucherType": "XC",
				"boeNum": "CTG-JX20122800657",
				"invoiceCount": "0",
				"approverDate": "2020-12-31 00:00:00",
				"userName": None,
				"coverStatus": "0",
				"voucherSeqValue": "200182000030152020",
				"approverNum": "99990008/SIT",
				"createdDt": "2021-07-09 15:49:50",
				"voucherName": "【CTG】共享系统-转账过账",
				"periodYear": "2020",
				"voucherStatus": "UNMATCH",
				"voucherTypeName": "共享系统-转账过账",
				"periodMonth": "12",
				"updatedDt": "2021-07-09 15:49:50",
				"voucherStatusName": "未匹配",
				"updatedUserId": "",
				"currencyCode": "USD"
			}
		],
		"ok": True
	}
	r = GetValues.get_dict(d, "id")
	s = GetValues.get_value_from_json_dict(d, "id")
	print(r, s, sep="\n")
